import request from '@/utils/request'
import type { Result, PageParams, PageResult, RoleCreateParams, RoleUpdateParams, RoleInfo } from '@/types/api'

export const roleApi = {
  // 分页查询角色
  async getRoleList(params: PageParams): Promise<Result<PageResult<RoleInfo>>> {
    return (await request.get<Result<PageResult<RoleInfo>>>('/admin/roles', { params })).data
  },

  // 创建角色
  async createRole(data: RoleCreateParams): Promise<Result<RoleInfo>> {
    return (await request.post<Result<RoleInfo>>('/admin/roles', data)).data
  },

  // 更新角色
  async updateRole(data: RoleUpdateParams): Promise<Result<string>> {
    return (await request.put<Result<string>>('/admin/roles', data)).data
  },

  // 删除角色
  async deleteRole(roleId: number): Promise<Result<string>> {
    return (await request.delete<Result<string>>(`/admin/roles/${roleId}`)).data
  },

  // 获取角色详情
  async getRoleDetail(roleId: number): Promise<Result<RoleInfo>> {
    return (await request.get<Result<RoleInfo>>(`/admin/roles/${roleId}`)).data
  }
}

// 导出单独的函数，用于兼容性
export const { getRoleList, createRole, updateRole, deleteRole, getRoleDetail } = roleApi 